#include<bits/stdc++.h>
using namespace std;

int a[500010];

int main()
{
	int n;
	cin>>n;
	for(int i = 1;i <= n;i++)
		cin>>a[i];
	long long ans = 0;
	for(int i = 1;i <= n+1;i++)
		ans += a[i]>a[i-1] ? a[i]-a[i-1] : 0;
	cout<<ans; 
	return 0;
}

